package com.cupcorn.lib.game;

import org.andengine.entity.sprite.TiledSprite;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.cupcorn.lib.Anchor;
import com.cupcorn.lib.Ratio;
import com.cupcorn.lib.Utils;

public class GameTiledSprite extends TiledSprite
{
	public GameRectangle	rectangle;
	public GameText				text;

	public GameTiledSprite(float pX, float pY, float pWidth, float pHeight, ITiledTextureRegion pTiledTextureRegion,
		VertexBufferObjectManager pVertexBufferObjectManager)
	{
		super(pX, pY, pWidth, pHeight, pTiledTextureRegion, pVertexBufferObjectManager);
	}
	
	public void setPosition(float pX, float pY, Anchor anchor, Ratio ratio)
	{
		super.setPosition(Utils.getPosX(pX, this.mWidth, anchor, ratio), Utils.getPosY(pY, mHeight, anchor, ratio));
	}
	
	public void destroy()
	{
		this.detachSelf();
		this.getTiledTextureRegion().getTexture().unload();
	}
	
	public void addRectangle()
	{
		rectangle = new GameRectangle(0, 0, mWidth, mHeight, getVertexBufferObjectManager());
		attachChild(rectangle);
	}
	
	public void addRectangle(GameRectangle rectangle)
	{
		this.rectangle = rectangle;
		rectangle.setPosition(Utils.getCenter(mWidth, rectangle.getWidthScaled()), Utils.getCenter(mHeight, rectangle.getHeightScaled()));
		attachChild(rectangle);
	}
	
	public void addText(GameText text)
	{
		this.text = text;
		text.setPosition(Utils.getCenter(mWidth, text.getWidthScaled()), Utils.getCenter(mHeight, text.getHeightScaled()));
		attachChild(text);
	}
	
}
